<?php

/**
* @Author Xman (admin@user.vn)
* @Website http://user.vn
* @Description Get rows from catid
*/

$catid = 20; # cat id
$num = 5; # amount rows to get
$striptext = 100; #cutout long text
$imgwidth = 52; #image width
$imgheight = 60; #image height


global $global_config, $db, $lang_global, $site_mods, $module_file;

list ( $catalias ) = $db->sql_fetchrow ( $db->sql_query ( "SELECT alias FROM `" . NV_PREFIXLANG . "_news_cat` WHERE catid=" . $catid . "" ) );
$content = '<table style="width:100%;border-bottom:1px #ccc dotted">';
list ( $id, $title, $alias, $publtime, $hometext, $homeimgalt, $homeimgthumb, $hitstotal ) = $db->sql_fetchrow ( $db->sql_query ( "SELECT id, title, alias, publtime, hometext, homeimgalt, homeimgthumb, hitstotal FROM `" . NV_PREFIXLANG . "_news_" . $catid . "` WHERE homeimgfile!='' AND `status`= 1 ORDER BY `publtime` DESC LIMIT 1" ) );
$link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=news&amp;" . NV_OP_VARIABLE . "=" . $catalias . "/" . $alias . "-" . $id;
$publtime = date ( 'd.m.Y h:i', $publtime );
$hometext = strip_tags ( $hometext );
$hometext = nv_clean60 ( $hometext, $striptext );
$homeimgthumb = explode ( '|', $homeimgthumb );
$imglink = NV_BASE_SITEURL . NV_FILES_DIR . '/news/' . $homeimgthumb [0];

$content .= '<tr><td style="text-align: justify;vertical-align:top;width:97%"><p style="margin:2px;font-weight:bold"><a href="' . $link . '">' . $title . '</a></p>';
$content .= '<img src="' . $imglink . '" alt="' . $homeimgalt . '" class="drop-shadow" onmouseover="this.style.opacity=0.5;this.filters.alpha.opacity=50" onmouseout="this.style.opacity=100;this.filters.alpha.opacity=100" style="opacity: 100;padding:1px;margin-right: 5px; float: left;width:' . $imgwidth . ';height:' . $imgheight . '"/>' . $hometext . '<br /></td></tr>';
$content .= '</table>';
$content .= '<table style="width:98%">';

$i = 0;
$sql = "SELECT id, title, alias, hometext, homeimgalt, homeimgthumb FROM `" . NV_PREFIXLANG . "_news_" . $catid . "` WHERE id!=" . $id . " AND `status`= 1 ORDER BY `publtime` DESC LIMIT " . ($num - 1) . "";
$result = $db->sql_query ( $sql );
while ( list ( $id, $title, $alias, $hometext, $homeimgalt, $homeimgthumb ) = $db->sql_fetchrow ( $result ) ) {
   $link = NV_BASE_SITEURL . "?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=news&amp;" . NV_OP_VARIABLE . "=" . $catalias . "/" . $alias . "-" . $id;
   $hometext = strip_tags ( $hometext );
   $hometext = nv_clean60 ( $hometext, $striptext );
   $title = strip_tags ( $title );
   $title = nv_clean60 ( $title, 40 );
   if (! empty ( $homeimgthumb )) {
      $homeimgthumb = explode ( '|', $homeimgthumb );
      $imglink = NV_BASE_SITEURL . NV_FILES_DIR . '/news/' . $homeimgthumb [0];
      $image = '<img src="' . $imglink . '" alt="' . $homeimgalt . '" class="drop-shadow" onmouseover="this.style.opacity=0.5;this.filters.alpha.opacity=50" onmouseout="this.style.opacity=100;this.filters.alpha.opacity=100" style="padding:1px;margin-right: 5px; float: left;width:50px;height:50px;opacity: 100;"/>';
   } else {
      $image = '';
   }
   if ($i == 2) {
      $content .= '<tr>';
   }
   $content .= '<td style="vertical-align:top;width:49%;padding-right: 5px; padding-top: 5px">' . $image . '<a title="' . $title . '" href="' . $link . '">' . $title . '</a></td>';
   if ($i == 4) {
      $content .= "</tr>";
   }
   $i ++;
}
$content .= '</table>';
?>